#include <iostream>
using namespace std;
void swap(int& a, int& b)
{
    int temp = a;
    a = b;
    b = temp;
    return;
}
void swap(int *a, int *b)
{
    int temp = *a;
    *a = *b;
    *b = temp;
    return;
}
void showArray(int a[],int len)
{
    for( int i = 0; i<len; i++)
        cout<<a[i]<<" ";
    cout<<endl;
}
bool bubble(int a[],int len)
{
    bool ifSwap = false;
    for(int i = 0; i<len-1; i++)
    {
        if(a[i]>a[i+1])
        {
            /*
            int temp = a[i];
            a[i] = a [i+1];
            a[i+1] = temp;
            */
            swap(a[i],a[i+1]);
            ifSwap = true;
        }
    }
    return ifSwap;
}
int main()
{
    int a[]  ={4,3,5,1,8};
    int len = 5;
    //swap(a[0],a[1]);
    //swap(&a[0],&a[1]);
    showArray(a,len);
    while(true)
    {
        bool ifSwap = bubble(a,len);
        showArray(a,len);
        if(!ifSwap)
            break;
    }

}
